<?php 
$this->Excel->openXls('files/templatePrm10kpi.xls');
$this->Excel->ajoutDonneeParColEtLigne(1,2,date('d/m/Y'));

$nbT=$kpiData['nbT'];
$months=$kpiData['months'];
$types=$kpiData['types'];
$i=0;
$lg=6;
$col=2;

?>
<h2 ><?php __('Number of Forms per month and per Status'); echo ' PRM10_KPI';  ?></h2>

<table class="formstatus">
    <thead>
        <tr>
            <th><?php __('Demand Type')  ?></th>
            <?php foreach ($months as $monthKey => $monthVal):  ?>
            <th><?php __(strftime('%b',  strtotime("2000-$monthKey-01")))  ?></th>
            <?php endforeach;  ?>
            <th><?php __('Year : '.date('Y'))  ?></th>
            <th><?php __('Year N-1 : '.(date('Y')-1))  ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($types as $typeKey => $typeVal):$col=2; ?>
        <?php 
        if($i%2>0) $cls='impair'; else $cls='pair';
        if($i%2>0) $this->Excel->impCells('B'.$lg.':P'.$lg);
        ?>
        <tr class="<?php echo $cls  ?>">
            <td><?php __($typeVal)  ?></td>
            <?php foreach ($nbT[$typeKey] as $key => $val):  ?>
            <td class="<?php ($key=="n" || $key=="n-1")? e('total'): e('monthTd'); ?>">
                <?php 
                        if(strlen($val)>0){
                            
                        $this->Excel->ajoutDonneeParColEtLigne($col,$lg,$val);
                        echo $val; 
                        }else{ 
                            echo '0'; 
                            $this->Excel->ajoutDonneeParColEtLigne($col,$lg,'0');
                        }                                                
                        $col++;
                ?>
            </td>
            <?php endforeach;  ?>
        </tr>
        <?php $i++; $lg++;  ?>
        <?php endforeach;  ?>
    </tbody>
</table>

<?php 
$this->Excel->colorCells('B5:P5',"A1BE4A");
$this->Excel->colorCells('O6:P15',"E1E3AF");
$this->Excel->saveAsXls('prm10kpi');
         $this->Excel->closeXls();
?>